package com.lovo;

import com.lovo.hb.dao.IRoleDao;
import com.lovo.hb.dao.IUserRoleDao;
import com.lovo.hb.dto.RoleDto;
import com.lovo.hb.entity.RoleEntity;
import com.lovo.hb.entity.UserRoleEntity;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;
import java.util.Map;

@SpringBootTest(classes = com.lovo.HibernateMain.class)
public class PowerT {
  @Autowired
    private IRoleDao roleDao;
  @Autowired
  private IUserRoleDao userRoleDao;
  @Test
  public void savaRole(){
       for(int i=0;i<10;i++){
           RoleEntity r=new RoleEntity();
           r.setRoleName("角色"+i);
           roleDao.save(r);
       }
  }

  @Test
  public void  roleT(){
  List<UserRoleEntity> list= userRoleDao.findAllByUserId(4);
      for (UserRoleEntity ur:list) {
          System.out.println(ur.getRole().getRoleName()+"/"+ur.getUser().getUserName());
      }
  }

    @Test
    public void  roleMap(){
   List<Map> maps=   userRoleDao.findAllByUserIdMap(4);
      for (Map map:maps){
          System.out.println(map.get("0")+"/"+map.get("1"));
      }
    }
    @Test
    public void  roleDto(){
      List<RoleDto> list=
      userRoleDao.findAllByUserName("林冲",0);
        System.out.println(list.size());
    }
    @Test
    public void  roleT2(){
     List<RoleEntity> list= roleDao.findAllByRoleName("角色2");
        System.out.println(list.size());
  }
  @Test
  public void  likeT(){
   List<RoleEntity> list=   roleDao.findAllByLikeRoleName("角色%");
      System.out.println(list.size());
  }
}
